package com.guigu.dao;



import com.ly.common.util.DBHelper;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class BookDao {

    public List<Map<String, Object>> queryAll() {
        DBHelper db = new DBHelper();
        String sql = "select * from books";

        return db.selectListMap(sql);
    }

    public List<Map<String, Object>> query(String name, String press, String author) {
        DBHelper db = new DBHelper();
        String sql = "select * from books where 1=1";
        List<Object> params = new ArrayList<>();
        if (name != null && name.trim().isEmpty() == false) {
            System.out.println(name);
            sql += " and bookname like concat('%', ? , '%')";
            params.add(name);
        }
        if(press!=null&&press.trim().isEmpty()==false){
            sql += " and bookpress like concat('%', ? , '%'  )";
            params.add(press);
        }
        if (author != null && author.trim().isEmpty() == false) {

            sql += " and bookauthor  like concat('%', ? , '%')";
            params.add(author);
        }
        return  db.selectListMap(sql,params.toArray());
    }
    public void add( List<Object> params){
        DBHelper db = new DBHelper();
       String sql = "insert into  books values (default,?,?,?,?,?,?)";
       db.update(sql,params.toArray());

    }
}

